package CompositePattern;

import java.util.ArrayList;
import java.util.List;

public class FileFolder extends AbstractComponent {     //容器节点：组合对象
    private String folderName;
    //容器由一个集合对象来充当容器
    private List<AbstractComponent> fileList = new ArrayList<AbstractComponent>();

    public FileFolder(String folderName) {
        this.folderName = folderName;
    }//构造器实例化文件夹名称

    @Override
    public void addComponent(AbstractComponent ac) {
        fileList.add(ac);
    }

    @Override
    public void removeComponent(AbstractComponent ac) {
        fileList.remove(ac);
    }

    @Override
    public AbstractComponent getComponent(int index) {
        return fileList.get(index);
    }

    @Override
    public void killVirus() {
        //要对容器节点进行病毒查杀:
        System.out.println("我们要对【"+folderName+"】进行查杀!");
        for (AbstractComponent ac:fileList)
            ac.killVirus();//递归调用


    }
}
